package com.woniu.adopt_web.config;

import com.woniu.adopt_web.service.PetArticleService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 文章aop 访问文章更新该文章访问量
 */
@Aspect
@Component
public class ArticleAspect {
    @Autowired
    PetArticleService petArticleService;

    @AfterReturning(value = "execution(* com.woniu.adopt_web.service.PetArticleService.queryById(..))", returning = "obj")
    public void updateArticleViews(JoinPoint joinPoint, Object obj) {
        Object[] args = joinPoint.getArgs();
        int id = (Integer) args[0];
        if (obj != null) {
            petArticleService.updateViews(id);
        }
    }
}
